/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.            */
/*                                                                 */
/*  NAME      = t__sqlserver_get_token_lst.c                       */
/*  NOTE      =                                                    */
/*  DATE      = 2015/02/13 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <CUnit/Basic.h>

#include <frmem.h>

#include <sqlserver/config.h>
#include <sqlserver/sqlserver_base_type.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

extern int __sqlserver_get_token_lst(Frbyte_Packet *p_st_data, unsigned char uc_token_type, int *p_i_ssl_flg,
                                     Frlist_header *p_lst_header);

void mylist_node_free(Frlist_node *p_st_node)
{
    if (p_st_node && p_st_node->data)
        frfree(p_st_node->data);

    return;
}

static void __case1(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    unsigned char uc_token_type = 0;
    int i_ssl_flg = FR_NO;
    Frlist_header *p_lst_header = NULL;

    i_ret = __sqlserver_get_token_lst(p_st_data, uc_token_type, &i_ssl_flg, p_lst_header);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_ssl_flg, FR_YES);
    return;
}

static void __case2(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    unsigned char uc_token_type = 0;
    int i_ssl_flg = FR_NO;
    Frlist_header *p_lst_header = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x01\x00\x01\x00", 4);

    p_lst_header = frlist_create();

    i_ret = __sqlserver_get_token_lst(p_st_data, uc_token_type, &i_ssl_flg, p_lst_header);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_ssl_flg, FR_NO);
    frlist_destroy(p_lst_header, mylist_node_free);

    bytebuff_free(&p_st_data);
    return;
}

static void __case3(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    unsigned char uc_token_type = 0;
    int i_ssl_flg = FR_NO;
    Frlist_header *p_lst_header = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x01\x01\x00", 3);

    p_lst_header = frlist_create();

    i_ret = __sqlserver_get_token_lst(p_st_data, uc_token_type, &i_ssl_flg, p_lst_header);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_ssl_flg, FR_YES);
    frlist_destroy(p_lst_header, mylist_node_free);

    bytebuff_free(&p_st_data);
    return;
}

int add_suite__sqlserver_get_token_lst(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __sqlserver_get_token_lst()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;


    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
